﻿<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Statistics_Edit.aspx.cs" Inherits="Topics_Statistics_Edit" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
    <link href="../css/style.css" rel="stylesheet" type="text/css" />
    <script src="../js/jquery-1.3.2.min.js" language="javascript" type="text/javascript"></script>
    <script src="../js/jquery-ui-1.7.3.custom.min.js" language="javascript" type="text/javascript"></script>
    <link href="../css/jquery-ui-1.7.3.custom.css" rel="Stylesheet" type="text/css" />
    <script src="../js/jquery.query.url.js" language="javascript" type="text/javascript"></script>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <table class="query_form_table">
            <tr>
                <th>
                    类型编号
                </th>
                <td>
                    <asp:TextBox ID="txtTypeId" runat="server" />
                    <asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server" 
                        ControlToValidate="txtTypeId" ErrorMessage="RequiredFieldValidator" 
                        ForeColor="#FF0066">非空</asp:RequiredFieldValidator>
                </td>
            </tr>
            <tr>
                <th>
                    标题
                </th>
                <td>
                    <asp:TextBox ID="txtTitle" runat="server" />
                    <asp:RequiredFieldValidator ID="RequiredFieldValidator2" runat="server" 
                        ControlToValidate="txtTitle" ErrorMessage="RequiredFieldValidator" 
                        ForeColor="#FF0066">非空</asp:RequiredFieldValidator>
                </td>
            </tr>
            <tr>
                <th>
                     提问
                </th>
                <td>
                    <asp:TextBox ID="txtQuestion" runat="server" />
                    <asp:RequiredFieldValidator ID="RequiredFieldValidator3" runat="server" 
                        ControlToValidate="txtQuestion" ErrorMessage="RequiredFieldValidator" 
                        ForeColor="#FF0066">非空</asp:RequiredFieldValidator>
                </td>
            </tr>
            <tr>
                <td colspan="2">
                    <asp:Button ID="btnSave" runat="server" ForeColor="#666633" 
                        onclick="btnSave_Click" Text="保存" />
                </td>
            </tr>
        </table>
        <div class="button_bar">
            <input id="btnAddList" value="添加新的选项" type="button" />
        </div>
       <table class="data_list_table">
             <tr>
                <th>编号</th><th>标题</th><th>投票数</th><th>操作</th>
            </tr>
            <asp:Repeater ID="repeater1" runat="server">
                <ItemTemplate>
                    <tr>
                        <td class="list_data_text"><%# Eval("id")%></td>
                        <td class="list_data_text"><%# Eval("Title")%></td>
                        <td class="list_data_text"><%# Eval("Count")%></td>
                        <td class="list_data_text">
                            <img ismodify="true" src="../images/bt_edit.gif" alt="修改" typeId='<%# Eval("TypeId") %>' tid='<%# Eval("id") %>' ttitle='<%# Eval("Title") %>' count='<%# Eval("Count") %>' title="修改" /> 
                                   <img isdelete="true" tid='<%# Eval("id") %>'  src="../images/bt_del.gif" alt="删除" />
                        </td>
                    </tr>
                </ItemTemplate>
            </asp:Repeater>
        </table>
    </div>
    </form>
        <div id="dialog" title="要修改的标题名称">
        <p id="content" style="text-align: center">
            <input id="txtMoifyTitle" type="text" />
        </p>
    </div>
    <div id="dialog3" title="要修改的标题名称">
        <p id="P2" style="text-align: center">
            <input type="hidden" id="hidOptionId" />
            标题
            <input type="text" id="txtOptionTitle" /><br />
            票数
            <input type="text" id="txtOptionCount" />
        </p>
    </div>
    
    <div id="dialog2" title="添加一个投票项">
        <p id="P1" style="text-align: center">
             <input id="txtAddTitle" type="text" />
        </p>
    </div>
    <input id="hidModifyId" type="hidden" />
    <script language="javascript" type="text/javascript">
        $(document).ready(function () {

            $("#btnAddList").click(function () {
                $('#dialog2').dialog("open");
            })

            $('#dialog').dialog({
                autoOpen: false,
                modal: true,
                width: 600,
                buttons: {
                    "取消": function () {

                        $(this).dialog("close");
                    },
                    "确定": function () {
                        var title = $("#txtMoifyTitle").val();
                        if (title == '') {
                            alert('标题不能为空');
                            return;
                        }
                        $.post("handler/VoteModify.ashx", { id: $("#hidModifyId").val(), title: title }, function (data) {
                            if (data == "1") {
                                alert('更新成功');
                            }
                            else {
                                alert("更新失败");
                            }
                        })
                    }
                }
            });
            $('#dialog2').dialog({
                autoOpen: false,
                modal: true,
                width: 400,
                buttons: {
                    "取消": function () {
                        $(this).dialog("close");
                    },
                    "确定": function () {
                        var title = $("#txtAddTitle").val();
                        var typeId = $.query.get("typeid");
                        if (title == '') {
                            alert('标题不能为空');
                            return;
                        }
                        $.post("handler/VoteAdd.ashx", { typeid: typeId, title: title }, function (data) {
                            if (data == "1") {
                                alert('更新成功');
                                $(this).dialog("close");
                                document.location = document.location;
                            }
                            else {
                                alert("更新失败");
                            }
                        })
                    }
                }
            });

            $('#dialog3').dialog({
                autoOpen: false,
                modal: true,
                width: 400,
                buttons: {
                    "取消": function () {
                        $(this).dialog("close");
                    },
                    "确定": function () {
                        var id = $("#hidOptionId").val();

                        var title = $("#txtOptionTitle").val()

                        var count = $("#txtOptionCount").val();

                        $.post("handler/VoteOptionModify.ashx", { title: title, count: count, id: id }, function (data) {
                            if (data == "1") {
                                alert("更新成功");
                                document.location = document.location;
                            }
                        })
                    }
                }
            });

            $("[ismodify=true]").click(function () {
                $("#hidOptionId").val($(this).attr("tid"));
                $("#txtOptionTitle").val($(this).attr("ttitle"));
                $("#txtOptionCount").val($(this).attr("count"));
                $('#dialog3').dialog("open");
            })
            $("[isdelete=true]").click(function () {
                if (!confirm('确定删除？')) {
                    return;
                }
                var id = $(this).attr("tid");
                $.post("handler/VoteOptionDelete.ashx", { id: id }, function (data) {
                    if (data == "1") {
                        alert("删除成功");
                        document.location = document.location;
                    }
                })
            })
        })
    </script>
</body>
</html>
